package com.ruoyi.common.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class OssConfig {
    @Value("${oss.endpoint}")
    private String endpoint;

    @Value("${oss.accessKeyId}")
    private String accessKeyId;
    
    @Value("${oss.accessKeySecret}")
    private String accessKeySecret;

    // 打印配置值（启动时观察控制台）
    @PostConstruct
    public void printConfig() {
        System.out.println(endpoint);
        System.out.println("accessKeyId: " + accessKeyId);
        System.out.println("accessKeySecret: " + accessKeySecret);
    }

    @Bean
    public OSS ossClient() {
        // 确保这里的accessKeyId不为null
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}